﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace Web.Controllers
{
    public class MonitorController : ApiController
    {
        public string GetLogin(string name,string password)
        {
            if ((name == "123")&&(password=="123"))
            {
                return "--Login:OK!!!--";
            }
            else
            {
                return "--Login:No!!!--";
            }
        }
        public string GetLogin(string name, string password,string Id)
        {
            Maticsoft.Model.T_Equipment monitor = new Maticsoft.Model.T_Equipment();
            Maticsoft.BLL.T_Equipment bll = new Maticsoft.BLL.T_Equipment();
            monitor = bll.GetModel(Id.Trim());
            if ((monitor.Name == name.Trim()) && (monitor.Password == password.Trim()))
            {
                return "--Login:OK!!!--";
            }

            return "--Login:No!!!--";
        }

        public string GetADC(string Datas,string Id)
        {
            if (Datas == null)
            {
                return "--Rec:Error1!!!--";   //没有连接上传
            }
            int leng = Datas.Length/4;
            for (int i = 0; i < leng; i++)
            {
                int m = 4 + 4 * i + i;
                 Datas =  Datas.Insert(m, ",");
            }
            Maticsoft.Model.T_Monitor monitor = new Maticsoft.Model.T_Monitor();
            Maticsoft.BLL.T_Monitor bll = new Maticsoft.BLL.T_Monitor();
            monitor.Time_Str = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
            monitor.Heart = "*"; monitor.Blood = "*";
            monitor.Id = System.Guid.NewGuid().ToString();
            monitor.Temp = "*"; monitor.NowTime = Datas;
            monitor.Equipment = Id;
            if(!bll.Add(monitor))
            {
                return "--Rec:Error2!!!--";  //没有保存
            }
            return "--Rec:Content!!!--";
        }

        public string GetADC(string Heart, string Blood, string Temp, string Id)
        {
            Maticsoft.Model.T_Monitor monitor = new Maticsoft.Model.T_Monitor();
            Maticsoft.BLL.T_Monitor bll = new Maticsoft.BLL.T_Monitor();
            monitor.Id = Id; monitor.Time_Str = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
            monitor.Heart = Heart; monitor.Blood = Blood;
            monitor.Temp = Temp; monitor.NowTime = "*";
            monitor.Equipment = Id;
            if (!bll.Add(monitor))
            {
                return "--Rec:Error2--";  //没有保存
            }
            return "--Rec:Content!!!--";
        }
    }
}
